﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using MyGeneration.dOOdads;
using MethodIT.Helper;

using Hr20.DAL;
using Hr20.BLL;
using Hr20.ProcessFlow;

namespace Appraisal.Web.ZB
{
    public partial class MyCheckTask : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string sUserID = DBController.GetInstance().GetAuthenticatedUserID();
            if (DBController.GetInstance().CheckUserRole(sUserID, "DeptAdmin"))
            {
                LoadData();
            }
            else
            {
                LoadData(sUserID);
            }
            
        }

        private void LoadData()
        {
            VW_CheckTask_List vw = new VW_CheckTask_List();
            vw.Where.Enable.Value = "-";
            vw.Query.AddOrderBy(VW_CheckTask_List.ColumnNames.CreateDate, WhereParameter.Dir.DESC);
            vw.Query.Load();
            dgAppraisal.DataSource = vw.DefaultView;
            dgAppraisal.DataBind();
        }

        private void LoadData(string UserID)
        {
            VW_CheckTask_List vw = new VW_CheckTask_List();
            vw.Where.Enable.Value = "N";
            vw.Where.UserID.Value = UserID;
            vw.Where.DataType.Value = "'tender','subject'";
            vw.Where.DataType.Operator = WhereParameter.Operand.In;
            vw.Query.AddOrderBy(VW_CheckTask_List.ColumnNames.CreateDate, WhereParameter.Dir.DESC);
            vw.Query.Load();
            dgAppraisal.DataSource = vw.DefaultView;
            dgAppraisal.DataBind();
        }

        //protected void dgAppraisal_SelectedIndexChanged(object sender, EventArgs e)
        //{
        //    string sType = dgAppraisal.SelectedItem.Cells[1].Text;
        //    string sID = dgAppraisal.SelectedItem.Cells[0].Text.ToLower();
        //    string sURL = "";

        //    switch (sType)
        //    {
        //        case "subject":
        //            sURL = "Appraisal/SubjectEdit.aspx?id=" + sID;
        //            break;
        //        case "tender":
        //            sURL = "ZB/NewTender.aspx?id=" + sID;
        //            break;
        //    }

        //    HelperURL.Redirect(sURL);
        //}

        protected void dgAppraisal_ItemDataBound(object sender, DataGridItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                HyperLink lnkAppraisal = (HyperLink)e.Item.Cells[7].Controls[0];
                string sType = e.Item.Cells[1].Text;
                string sID = e.Item.Cells[0].Text.ToLower();
                string sURL = "";

                switch (sType)
                {
                    case "subject":
                        sURL = "Appraisal/SubjectEdit.aspx?id=" + sID;
                        break;
                    case "tender":
                        sURL = "ZB/NewTender.aspx?id=" + sID;
                        break;
                    case "check":
                        sURL = "ZB/NewCheckTask.aspx?id=" + sID;
                        break;
                }

                //lnkAppraisal.Attributes.Add(ConstantController.JS_ONCLICK, HelperURL.GetShowWindowModalStringWithParams(sURL, 1024, 768));
                //lnkAppraisal.Attributes.Add(ConstantController.JS_ONCLICK, HelperURL.GetShowWindowModalStringWithParams(sURL,1024,768));
                lnkAppraisal.Attributes.Add(ConstantController.JS_ONCLICK, HelperURL.GetShowWindowString(sURL));
            }
        }
    }
}